package cn.tinlan.shopcoin.app.mine.view;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.drawable.Drawable;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import cn.tinlan.shopcoin.R;

/**
 * Created by Mortimer on 2018/11/23. 16:43
 * 佛祖🙏，永无bug。
 */
public class PersonalItemView extends LinearLayout {

    private View bottomLine;
    private ImageView left_img;
    private TextView item_text;
    private TextView right_text;
    public boolean ishiden;
    public String itemtext;
    public Integer itemicon;


    public PersonalItemView(Context context) {
        this(context,null);
    }

    public PersonalItemView(Context context, @Nullable AttributeSet attrs) {
        this(context, attrs,0);
    }

    public PersonalItemView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        View view =    LayoutInflater.from(context).inflate(R.layout.view_mine_item,this);
        Log.i("personal---->>>","error");

        bottomLine = view.findViewById(R.id.bottom_line);
        left_img = view.findViewById(R.id.left_img);
        item_text = view.findViewById(R.id.item_text);
        right_text = view.findViewById(R.id.item_right_text);
        TypedArray ta = getContext().obtainStyledAttributes(attrs,R.styleable.personal_item_view);

        try {
            Drawable mDrawableLeft = ta.getDrawable(R.styleable.personal_item_view_show_leftimg);
            String mStringLeft = ta.getString(R.styleable.personal_item_view_show_text);
            String mStringRight = ta.getString(R.styleable.personal_item_view_show_right_text);
            Boolean isShowRightIcon = ta.getBoolean(R.styleable.personal_item_view_show_bottomline, true);
            if (mDrawableLeft != null) {
                left_img.setImageDrawable(mDrawableLeft);
            }
            if (mStringLeft != null){
                item_text.setText(mStringLeft);
            }
            if (mStringRight != null){
                right_text.setText(mStringRight);
            }else {
                right_text.setVisibility(View.GONE);
            }
            bottomLine.setVisibility(isShowRightIcon == true ? View.VISIBLE : View.GONE);
        }finally {
            ta.recycle();
        }
//
//        bottomLine.setVisibility(ta.getBoolean(R.styleable.personal_item_view_show_bottomline,true) == true ? View.VISIBLE : View.GONE );
//        item_text.setText(ta.getString(R.styleable.personal_item_view_show_text));
//        left_img.setBackgroundResource(ta.getResourceId(R.styleable.personal_item_view_show_leftimg,R.drawable.search));


    }
}
